package com.example.arithmeticleetcode.leetcode.october;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-16 09:21
 **/
public class Demo07 {

    public static void main(String[] args) {

        String[] str1 = {"alice,20,800,mtv", "alice,50,100,beijing"};
        System.out.println(invalidTransactions(str1)); //["alice,20,800,mtv","alice,50,100,beijing"]

        String[] str2 = {"alice,20,800,mtv", "alice,50,1200,mtv"};
        System.out.println(invalidTransactions(str2)); //["alice,50,1200,mtv"]

        String[] str3 = {"alice,20,800,mtv", "bob,50,1200,mtv"};
        System.out.println(invalidTransactions(str3)); //["bob,50,1200,mtv"]
    }

    public static List<String> invalidTransactions(String[] transactions) {
        List<String> list = new ArrayList<>();

        for (int i = 0, len = transactions.length; i < len; i++) {
            String transaction = transactions[i];
            String[] split = transaction.split(",");
            if (Integer.valueOf(split[2]) > 1000) {
                list.add(transaction);
                continue;
            }
            for (int j = 0; j < len; j++) {
                if (i == j) continue;
                String[] tempStr = transactions[j].split(",");
                if (split[0].equals(tempStr[0]) && !split[3].equals(tempStr[3]) && (Math.abs(Integer.valueOf(split[1]) - Integer.valueOf(tempStr[1])) <= 60)) {
                    list.add(transaction);
                    break;

                }

            }
        }
        return list;
    }
}
